<%--
  Created by IntelliJ IDEA.
  User: 67693
  Date: 2021/7/21
  Time: 14:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <meta charset="utf-8">
    <title>testOrderInfo</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/library/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/library/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" value="${id}">
    <div class="layui-form-item">
        <label class="layui-form-label ">收件人</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" readonly name="username" id="username" value="${username}">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">收件地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="required" lay-reqtext="地址不能为空" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">付款方式</label>
        <div>
            <input type="radio" name="paymethod" value="" title="货到付款" checked>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">付款金额（元）</label>
        <div class="layui-input-block">
            <input type="text" readonly name="price" value="${price}" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="confirmBuy">确认购买</button>
        </div>
    </div>
</div>
<script src="/library/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(confirmBuy)', function (data) {
            var datas=data.field;//form单中的数据信息
                //向后台发送数据提交添加
                $.ajax({
                    url:"/orderSubmit",
                    type:"POST",
                    data: {
                        goodsid:datas.id,
                        username:datas.username,
                        address:datas.address,
                        price:datas.price
                    },
                    success:function(result){
                        if(result.code==0){//如果成功
                            layer.msg("下单成功",{
                                icon:6,
                                time:500
                            },function(){
                                parent.window.location.reload();
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            })
                        }else{
                            layer.msg(result.msg);
                        }
                    }
                })
            return false;
        });

    });
</script>
</body>
</html>
